<?php

require ('core/shop.php');


//查询订单主表类
quanli_require('module/base/bill/billSearch.class.php');


if (!isset($_REQUEST['bill_no']) || empty($_REQUEST['bill_no'])) {
	die('缺少参数');
}

$bill_array = array(); //订单商品数组
$bill_no = $_REQUEST['bill_no'];

//首先把传递过来的bill_no根据逗号分隔成数组
$bill_no_array = explode(',',$bill_no);
for($i = 0 ; $i<count($bill_no_array); $i++){
	//查询打印商品信息
	$arg_array = array(
			'bill_no' =>$bill_no_array[$i]
	);

	//订单查询类
	$bill_arraySearch = new billSearch();
	
	//查询订单主表信息 bill_master
	$temp_array  = $bill_arraySearch->searchQueryBill( $arg_array );
	
	$bill_array = $temp_array[0];
	$PRTIME = ( $bill_array['send_end_time']=="00:00" || $bill_array['send_end_time']==$bill_array['send_start_time'] ) ? $bill_array['send_start_time'] : ( $bill_array['send_start_time'].'-'.$bill_array['send_end_time'] );//配送时间
	
	
	$temp_array1 = $bill_arraySearch->searchBillInfo( $arg_array );
	$bill_array1 = $temp_array1[0];
	
	//查询订单商品表 bill_goods
	$bill_goods_array = $bill_arraySearch->searchBillGoods( $arg_array );
	foreach ( $bill_goods_array as $k=>$val ){
		$goods_array_count ++;
	
		$bill_candle_amount += $val['candle_amount'];
		$bill_extra_candle_amount += $val['extra_candle_amount'];
		$birthday_card = $val['birthday_card'].',';
	
	
	}
	
	$print_array[$i] = array(
			'PSRQ' => $bill_array['send_date'],
			'DDH' => $bill_array['bill_no'],
			'PSY' => $bill_array['distribution_technicia'],
			'XDSJ' => $bill_array['createTime'],
			'PSSJ' => $PRTIME,
			'PSDZ' => $bill_array1['deliver_all_address'],
	
			'YSJE' => $bill_array['bill_receivable_money'],
	
			'SHR' =>$bill_array['deliver_name'],
	
			'LXSJ' => $bill_array['deliver_mobile'],
			'PSBZ' => $bill_array['remark'],
			
			
	
	
	
	);
	//赠送蜡烛数量
	if( $bill_candle_amount ){
		$zs= $bill_candle_amount;
	}
	
	//额外蜡烛数量
	if( $bill_extra_candle_amount ){
		$ew= $bill_extra_candle_amount;
	}
	//发票信息
	if($bill_array['invoice_title']==''){
		$print_array[$i]['FPXX']=$bill_array['invoice_content'];
	}else{
		$print_array[$i]['FPXX']=$bill_array['invoice_title'].','.$bill_array['invoice_content'];
	}
	//生日牌
	if($birthday_card==','){
		$print_array[$i]['XRP'] = ' ';
	}else{
		$print_array[$i]['XRP'] = $birthday_card;
	}
	if($zs+$ew>0){
		$print_array[$i]['LZ']='是';
	
	}	
	
	
}



for($i=0; $i<count($bill_no_array); $i++){
	
	$a[$i]=$print_array[$i];
	
}

$xml_string = "<xml>";

foreach ($a as &$b){
	$xml_string .="<row>";
		foreach($b as $key => $val) {
    		$xml_string .= "<$key>$val</$key>";
		}
	$xml_string .="</row>";
}

$xml_string .= "</xml>";


header("Content-Type: text/html; charset=utf-8"); 
echo $xml_string;